package me.mcx.mcx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import me.mcx.common.annotation.Log;
import me.mcx.common.core.controller.BaseController;
import me.mcx.common.core.domain.AjaxResult;
import me.mcx.common.core.page.TableDataInfo;
import me.mcx.common.enums.BusinessType;
import me.mcx.common.utils.poi.ExcelUtil;
import me.mcx.mcx.domain.McxCase;
import me.mcx.mcx.service.IMcxCaseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 案例管理Controller
 * 
 * @author mcx
 * @date 2024-09-21
 */
@RestController
@RequestMapping("/mcx/case")
public class McxCaseController extends BaseController
{
    @Autowired
    private IMcxCaseService mcxCaseService;

    /**
     * 查询案例管理列表
     */
    @PreAuthorize("@ss.hasPermi('mcx:case:list')")
    @GetMapping("/list")
    public TableDataInfo list(McxCase mcxCase)
    {
        startPage();
        List<McxCase> list = mcxCaseService.selectMcxCaseList(mcxCase);
        return getDataTable(list);
    }

    /**
     * 导出案例管理列表
     */
    @PreAuthorize("@ss.hasPermi('mcx:case:export')")
    @Log(title = "案例管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, McxCase mcxCase)
    {
        List<McxCase> list = mcxCaseService.selectMcxCaseList(mcxCase);
        ExcelUtil<McxCase> util = new ExcelUtil<McxCase>(McxCase.class);
        util.exportExcel(response, list, "案例管理数据");
    }

    /**
     * 获取案例管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mcx:case:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mcxCaseService.selectMcxCaseById(id));
    }

    /**
     * 新增案例管理
     */
    @PreAuthorize("@ss.hasPermi('mcx:case:add')")
    @Log(title = "案例管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody McxCase mcxCase)
    {
        return toAjax(mcxCaseService.insertMcxCase(mcxCase));
    }

    /**
     * 修改案例管理
     */
    @PreAuthorize("@ss.hasPermi('mcx:case:edit')")
    @Log(title = "案例管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody McxCase mcxCase)
    {
        return toAjax(mcxCaseService.updateMcxCase(mcxCase));
    }

    /**
     * 删除案例管理
     */
    @PreAuthorize("@ss.hasPermi('mcx:case:remove')")
    @Log(title = "案例管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mcxCaseService.deleteMcxCaseByIds(ids));
    }
}
